
//video model
const kVideoVodMode         = 0;        // 点播模式
const kVideoLiveMode        = 1;        // 直播模式
const kVideoRealtimeLiveMode= 2;        // 实时直播模式，通过丢帧来播放最实时的视频

//Downloader Protocol.
const kProtoHttp            = 0;
const kProtoWebsocket       = 1;
const kProtoRtmp            = 2;

//Downloader request.
const kGetFileInfoReq       = 1000;
const kDownloadFileReq      = 1001;
const kCloseDownloaderReq   = 1002;

//Downloader response.
const kGetFileInfoRsp       = 1100;
const kFileData             = 1101;
const kDownloadStopped      = 1102;

//Decoder request.
const kInitDecoderReq       = 2000;
const kUninitDecoderReq     = 2001;
const kOpenDecoderReq       = 2002;
const kCloseDecoderReq      = 2003;
const kFeedDataReq          = 2004;
const kStartDecodingReq     = 2005;
const kPauseDecodingReq     = 2006;
const kSeekToReq            = 2007;
const kStopRtmpDownloadReq  = 2008;
const kChangeSourceReq      = 2009;
const kDownloadFileEnd      = 2010;
const kDecodeReq            = 2011;
const kPauseDecodeReq       = 2012;
const kResumeDecodeReq      = 2013;

//Decoder response.
const kInitDecoderRsp       = 2100;
const kUninitDecoderRsp     = 2101;
const kOpenDecoderRsp       = 2102;
const kCloseDecoderRsp      = 2103;
const kVideoFrame           = 2104;
const kAudioFrame           = 2105;
const kStartDecodingRsp     = 2106;
const kPauseDecodingRsp     = 2107;
const kDecodeFinishedEvt    = 2108;
const kRequestDataEvt       = 2109;
const kSeekToRsp            = 2110;
const kDecodeRsp            = 2111;
const kChangeSourceRsp      = 2112;
const kPauseDecodeRsp       = 2113;
const kResumeDecodeRsp      = 2114;

// RTMP状态
const kRtmpStatusClosed     = 0;
const kRtmpStatusConnecting = 1;
const kRtmpStatusConnected  = 2;
const kRtmpStatusPlaying    = 3;

// Error Code
const ErrorSuccess            = 0;
const ErrorInvalidParam       = 1;
const ErrorInvalidState       = 2;
const ErrorInvalidData        = 3;
const ErrorInvalidFormat      = 4;
const ErrorNULLPointer        = 5;
const ErrorOpenFileError      = 6;
const ErrorEof                = 7;
const ErrorFFmpegError        = 8;
const ErrorOldFrame           = 9;
const ErrorOutOfMemory        = 10;
const ErrorNeedMoreData       = 11;
const ErrorNotSupport         = 12;

function Logger(module) {
    this.module = module;
}

Logger.prototype.log = function (line) {
    console.log("[" + this.currentTimeStr() + "][" + this.module + "]" + line);
}

Logger.prototype.logError = function (line) {
    console.log("[" + this.currentTimeStr() + "][" + this.module + "][ER] " + line);
}

Logger.prototype.logInfo = function (line) {
    console.log("[" + this.currentTimeStr() + "][" + this.module + "][IF] " + line);
}

Logger.prototype.logDebug = function (line) {
    console.log("[" + this.currentTimeStr() + "][" + this.module + "][DT] " + line);
}

Logger.prototype.currentTimeStr = function () {
    var now = new Date(Date.now());
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    var hour = now.getHours();
    var min = now.getMinutes();
    var sec = now.getSeconds();
    var ms = now.getMilliseconds();
    return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec + ":" + ms;
}
